(function() {
	async function getSeat() {
		let {
			data: r
		} =
		await axios({
			url: 'data/seat_list.json'
		})
		let trs = ``;
		r.forEach(function(val, index) {
			let tr = `<tr><td width="30px">${index + 1}</td>`; //序号
			let td = ``;
			val.forEach(function(s) { //构建座位
				if (s == null) {
					td += `<td width="30px"></td>`;
				} else {
					if (s.seat_status == 1) {
						td +=
							`<td width="30px" class="hand" sid="${s.seat_id}"><img src="./img/seat01.png"></td>`;
					} else if (s.seat_status == 2) {
						td += `<td width="30px"><img src="./img/seat02.png"></td>`;
					} else if (s.seat_status == 3) {
						td += `<td width="30px"><img src="./img/seat03.png"></td>`;
					}
				}
			})

			tr += td + `</tr>`;
			console.log(tr);
			trs += tr;
		})
		$('tbody').append(trs);

		//可选座位绑定事件
		$('.hand').click(function() {
			//改变选中座位的图片
			const img = $(this).children();
			img.attr('src', './img/seat03.png');
			//获取选中座位的id
			let sid = $(this).attr('sid');
			//val是座位数组
			let seat = {};
			r.forEach(function(val) {
				val.forEach(function(s) {
					if (s != null && s.seat_id == sid) { //(!s)
						let st =
							`<div class="text-red py-1 px-2 border-red-1 rounded mr-2 mb-2">${s.seat_row}排${s.seat_column}座</div>`;
						if ($('.selected').children().length < 6) {
							$('.selected').append(st);
						} else {
							alert("最多选6个座位")
						}

					}
				})
			})
		})
	}
	getSeat();
})()
